﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace WBInfo
{
    public class FileAction
    {
        public static string fundCodeFileName = "fundCode.txt";
        /*检查基金代码文件是否存在,若存在则读取基金代码并返回,若不存在则新建代码文件
        文件存储位置与应用程序同级*/    
        public static Dictionary<string,object> checkFundFile()
        {
            Dictionary<string,object> outAry = new Dictionary<string, object>();
            try
            {
                string appFilePath = Environment.CurrentDirectory;
                string filePath = appFilePath + "\\" + fundCodeFileName;
                if (!File.Exists(filePath))
                {
                    File.Create(filePath).Close();
                    outAry.Add("result","No data");
                    return outAry;
                }
                StreamReader sr = new StreamReader(filePath,Encoding.Default);
                String line;
                List<string> list = new List<string>();
                while ((line = sr.ReadLine()) != null)
                {
                    list.Add(line);
                }
                sr.Close();
                
                outAry.Add("result","success");
                outAry.Add("count",list.Count);
                outAry.Add("data",list.ToArray());
            }
            catch (Exception e)
            {
                outAry.Add("result",e.Message);
            }
            return outAry;
        }
    }
}